package jdbc.c3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.beans.PropertyVetoException;
import java.sql.*;

public class Test {
    public static void main(String[] args) throws PropertyVetoException, SQLException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql:///test_database?useSSL=false&useServerPreStmts=true&allowPublicKeyRetrieval=true");
        dataSource.setUser("nanako");
        dataSource.setPassword("nanako");

        Connection conn = dataSource.getConnection();

        // 第三步：选择对应的sql语句
        Statement stat = conn.createStatement();
        // 提交到数据库
        ResultSet rs = stat.executeQuery("select * from employees");
        while (rs.next()) { // 判断当前行是否有数据
            System.out.print(rs.getInt(1) + " ");
            System.out.print(rs.getString(2) + " ");
            System.out.print(rs.getString(3) + " ");
            System.out.print(rs.getString(4) + " ");
            System.out.print(rs.getInt(5) + " ");
            System.out.print(rs.getString(6) + " ");
            System.out.print(rs.getString(7) + " ");
            System.out.print(rs.getString(8));
            System.out.println();
        }
        rs.close();
        conn.close();
    }
}

